unit setmaximumformunit;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, Spin,
  ButtonPanel, LCLTranslator;

type

  { TSetMaximumForm }

  TSetMaximumForm = class(TForm)
    DecisionButtonPanel: TButtonPanel;
    MaximumLabel: TLabel;
    MaximumSpinEdit: TSpinEdit;
    procedure CancelButtonClick(Sender: TObject);
    procedure OKButtonClick(Sender: TObject);
  private
    ResultValue: Integer;
  public
    function RequestValue(OriginalValue: Integer; MaxValue: Integer = 999): Integer;
  end;

var
  SetMaximumForm: TSetMaximumForm;

implementation

{$R *.lfm}

{ TSetMaximumForm }

procedure TSetMaximumForm.OKButtonClick(Sender: TObject);
begin
  ResultValue := MaximumSpinEdit.Value;
  Close;
end;

procedure TSetMaximumForm.CancelButtonClick(Sender: TObject);
begin
  Close;
end;

function TSetMaximumForm.RequestValue(OriginalValue: Integer; MaxValue: Integer
  ): Integer;
begin
  ResultValue := OriginalValue;
  MaximumSpinEdit.MaxValue := MaxValue;
  MaximumSpinEdit.Value := OriginalValue;
  ShowModal;

  RequestValue := ResultValue;
end;

end.

